<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta name="description" content="">
<meta http-equiv="x-dns-prefetch-control" content="on">
<title>搭车详情 - 创建者查看</title>
<link href="../imgv2/css/css.css" rel="stylesheet" type="text/css">
</head>

<body class="whitebg">
	<!--wrap start-->
	<section id="wrap">
		<section class="black_bg">
			<div class="popup_img">
				<img src="../imgv2/popup_send_friend_car.png" width="100%"
					height="100%" />
			</div>
		</section>
		<section class="detailtitlebar">
			<img src="img/user_pic.png" width="100%" height="100%"
				class="tripuser" />
			<ul class="listitem h120">
				<li class="userinfo">
					<p class="username">永远的永远 创建的</p>
					<p class="status_green greenline">等待中</p>
				</li>
				<li class="d_triptitle"><i class="iconfont mr10">&#xe606;</i>当前位置：黄河路111号</li>
			</ul>
		</section>
		<section class="subtitle">给好友的一句话</section>
		<section class="citylist whitebg">
			<ul class="listitem bottomline">
				<div class="message">我在路边麦当劳门口等你。这里下雨了，记得带一把雨伞。</div>
			</ul>
		</section>
		<section class="steparea">
			<div class="itemone">
				<div class="userico">
					<i class="iconfont">&#xe611;</i>
				</div>
				<div class="textarea">永远的永远 发起搭车请求</div>
			</div>
			<div class="itemcenter">
				<div class="userico40">
					<i class="iconfont">&#xe600;</i>
				</div>
				<div class="textarea">等待好友接受</div>
			</div>
			<div class="itembottom">
				<div class="userico_gray">
					<i class="iconfont">&#xe611;</i>
				</div>
				<div class="textarea">
					<button class="bigbtn button"
						onClick="this.className='button_d bigbtn'"
						onmouseout="this.className='bigbtn button'">发送搭车请求给好友</button>
				</div>
			</div>
			<div class="stepline">
				<div class="stepline_blue" style="height: 40%"></div>
			</div>
		</section>
	</section>
	<!--wrap end-->

</body>
<script src="../jsv2/jQuery/jquery-1.11.2.min.js"></script>
<script src="../jsv2/common.js"></script>
<script type="text/javascript" src="../jsv2/QueryStringParser.js"></script>
<script type="text/javascript" src="../jsv2/jquery.json.min.js"></script>
<script type="text/javascript" src="../jsv2/jsonMsg.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
<script language="javascript">
var mapObj, geolocation, markerFF, markers = [], geoSuccessListener, geoErrorListener;
var toolBar;
var locationInfo;
var windowsArr = [];
var marker = [];
var memberList = [];
var latLon = "";
var _lat = null;
var _lon = null;
var receiverId;
var openId = queryString.getParam("openid");
var pickupId = queryString.getParam("pickupid");
var customMarker = new AMap.Marker({
	offset:new AMap.Pixel(-14,-34),//相对于基点的位置
	icon:new AMap.Icon({  //复杂图标
		size:new AMap.Size(27,36),//图标大小
		image:"http://webapi.amap.com/images/custom_a_j.png", //大图地址
		imageOffset:new AMap.Pixel(-28,0)//相对于大图的取图位置
	})
});

function setLocation() {
    if (geolocation) {
        //geolocation.getCurrentPosition();
        geolocation.watchPosition();
    }
    else {
        setTimeout(setLocation, 10000);
    }
}

//获取团员地址时，如果某个人团员下线了，则把头像从地图上移除掉
function deleteNotInMarkers(memberData) {
    var flag = true;
    for (var i = 0, j = markers.length; i < j; i++) {
        var m = markers[i];
        flag = true;
        for (var _i = 0, _j = memberData.length; _i < _j; _i++) {
            var md = memberData[_i];
            if (m.getTitle() === md.OpenID) {
                flag = false;
                break;
            }
        }
        if (flag) {
            m.setMap(null);
        }
    }
}

//显示所有人的位置头像
function showAllPositions(allPositions,headImg,nickNm) {
		if(allPositions!=null && allPositions.Loc!=null){
	    setMemberLocation(allPositions.OpenID, allPositions.Loc.Longitude/1000000, allPositions.Loc.Latitude/1000000, headImg, false, 20,nickNm,allPositions.EstimateTime,allPositions.Distance);
  	}
}

//当开着这个页面的时候，上传位置信息
function updateMemberPositions(_lat, _lng) {
	
		var dataStr = {  
	    PickupID: pickupId,
			OpenID : receiverId
		}; 
		var bodyStr = popBody('DynamicInfoPickup',dataStr);
		var request = popRequest('DynamicInfoPickup',openId,bodyStr);
		//调用了jquery.json 库  
		var encoded = $.toJSON( request );  
		var jsonStr = encoded;  
		
		$.ajax({  
	    	url : actionStr,  
	    	type : 'POST',  
	    	data : jsonStr,  
	    	dataType : 'json',  
	    	contentType : 'application/json',  
	    	success : function(data, status, xhr) {  
	    		//Do Anything After get Return data  
	    		
	    		if(data.portalResp.Data!=null){
						showAllPositions(data.portalResp.Data,recImg,recNickname);
					}
					//deleteNotInMarkers(data.portalResp.Data);		
	    	},  
	    	Error : function(xhr, error, exception) {  
	    		    // handle the error.    
	            alert(exception.toString());  
	    	}  
		});  
}

function geoInit(isCenter) {
    geolocation = new AMap.Geolocation({
        enableHighAccuracy: true, //是否使用高精度定位，默认:true  
        timeout: 100000,          //超过10秒后停止定位，默认：无穷大  
        maximumAge: 0,           //定位结果缓存0毫秒，默认：0  
        convert: true,           //自动偏移坐标，偏移后的坐标为高德坐标，默认：true  
        showButton: false,        //显示定位按钮，默认：true  
        buttonPosition: 'LB',    //定位按钮停靠位置，默认：'LB'，左下角  
        buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)  
        showMarker: true,        //定位成功后在定位到的位置显示点标记，默认：true  
        markerOptions: { title: "locationIMG", offset: { x: -10, y: 20 }, icon: new AMap.Icon({ image: "http://webapi.amap.com/theme/v1.2/my_location.png", size: new AMap.Size(16, 16), imageOffset: { x: -24, y: -2} }) },
        showCircle: false,        //定位成功后用圆圈表示定位精度范围，默认：true  
        panToLocation: isCenter,     //定位成功后将定位到的位置作为地图中心点，默认：true  
        zoomToAccuracy: true      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false  
    });
    mapObj.addControl(geolocation);
    geoSuccessListener = AMap.event.addListener(geolocation, 'complete', OnComplete); //返回定位信息,初始时定位后设为地图中心点  
    geoErrorListener = AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息  
}

function geoRemove() {
    mapObj.removeControl(geolocation);
    AMap.event.removeListener(geoSuccessListener);
    AMap.event.removeListener(geoErrorListener);
    if ($("div[title='locationIMG']")) {
        $("div[title='locationIMG']").parent().remove();
    }
}


function mapInit(center) {
    mapObj = new AMap.Map('iCenter', { level: 15 });
    
    mapObj.plugin(["AMap.ToolBar"],function(){		
			toolBar = new AMap.ToolBar();
			mapObj.addControl(toolBar);		
		});
		
    mapObj.plugin('AMap.Geolocation', function () {
        geoInit(false);
    });
    AMap.event.addListener(mapObj, 'dragstart', function (e) {//移动地图后再定位时不设为地图中心点
        geoRemove();
        geoInit(false);
        setLocation()
    });
		//var pageURL = location.href.split('#')[0];
		//pageURL = pageURL.substring(0,pageURL.indexOf("trip_voice"))+
    //终点
    var endmarker = new AMap.Marker({
			icon:new AMap.Icon({  //复杂图标
				image:"img/dis_icon.png" //大图地址
			})
		});
    endmarker.setPosition(center);                 
    endmarker.setMap(mapObj);
    mapObj.setZoomAndCenter(14, center);
};

function getExistsInMarkers(titleOpenID) {
    for (var i = 0; i < markers.length; i++) {
        var m = markers[i];
        if (m.getTitle() === titleOpenID) {
            return m;
        }
    }
    return null;
}

function setMemberLocation(_oID, _lng, _lat, _imageUrl, _isLeader, currentMember,nickNameIn,estimateTime,distance) {
	var _m = getExistsInMarkers(_oID);
	if (_m) {
	    if (currentMember > 1) {
	        _m.setzIndex(currentMember);
	    }
	    _m.setMap(mapObj);
	    _m.setPosition(new AMap.LngLat(_lng, _lat));
	}
	else {
	    var marker = new AMap.Marker({});
	
	    //自定义点标记内容     
	    var markerContent = document.createElement("div");
	    
	    if(_isLeader){
	    	markerContent.className = "user_popup";
	    	//头像
	    	var markerContentDiv2 = document.createElement("div");
	    	markerContentDiv2.className = "user_img_blue";
	    	
	    	var markerP2 = document.createElement("p");
		    var markerImg2 = document.createElement("img");
		    markerImg2.src = _imageUrl !== null && _imageUrl !== "" ? _imageUrl : "img/friend_pic.png";
		    markerImg2.width = 50;
		    markerImg2.height = 50;
		    markerP2.appendChild(markerImg2);
		    markerContentDiv2.appendChild(markerP2);
		    
		    var markerP22 = document.createElement("p");
		    markerP22.className = "user_group_name";
		    markerP22.innerHTML=nickNameIn;
		    markerContentDiv2.appendChild(markerP22);
		
		    markerContent.appendChild(markerContentDiv2);
		    
		    var markerContentDiv3 = document.createElement("div");
		    markerContentDiv3.className = "downarrow";	
		    var markerImg3 = document.createElement("img");
		    markerImg3.src = "img/arrow_popup_blue.png";

		    markerContentDiv3.appendChild(markerImg3);
		    markerContent.appendChild(markerContentDiv3);

	  	}else{
	  		markerContent.className = "user_popup_info";
	    	//头像
	    	var markerContentDiv2 = document.createElement("div");
	    	markerContentDiv2.className = "user_img_info";
	    	
	    	var markerContentDiv3 = document.createElement("div");
	    	markerContentDiv3.className = "user_img_area";
	    	var markerImg3 = document.createElement("img");
		    markerImg3.src = _imageUrl !== null && _imageUrl !== "" ? _imageUrl : "img/friend_pic.png";

		    markerContentDiv3.appendChild(markerImg3);
		    markerContentDiv2.appendChild(markerContentDiv3);
		    
		    var markerContentDiv4 = document.createElement("div");
	    	markerContentDiv4.className = "popup_info";
	    	
	    	var markerP22 = document.createElement("p");
		    markerP22.className = "line_info";
		    markerP22.innerHTML=nickNameIn;
		    markerContentDiv4.appendChild(markerP22);
		    
		    var markerP33 = document.createElement("p");
		    markerP33.className = "line_info";
		    markerP33.innerHTML=distance+"公里";
		    markerContentDiv4.appendChild(markerP33);
		    
		    var markerP44 = document.createElement("p");
		    markerP44.innerHTML=estimateTime+"分钟";
		    markerContentDiv4.appendChild(markerP44);
		    
		    markerContentDiv2.appendChild(markerContentDiv4);
		    markerContent.appendChild(markerContentDiv2);
	  	}
	    
	    
	
	    if (currentMember > 1) {
	        marker.setzIndex(currentMember);
	    }
	
	    marker.setTitle(_oID)
	    marker.setContent(markerContent); //更新点标记内容
	    marker.setPosition(new AMap.LngLat(_lng, _lat)); //更新点标记位置                    
	    marker.setMap(mapObj);
			mapObj.setZoomAndCenter(14, new AMap.LngLat(_lng, _lat));
			mapObj.setFitView();
	    markers.push(marker);
	}
}

function OnComplete(data) {
		_lat = data.position.getLat();
		_lon = data.position.getLng();
    setMemberLocation(openId, data.position.getLng(), data.position.getLat(), imageURL, true, 20,nickName,"","");
    updateMemberPositions(data.position.getLat(), data.position.getLng());                
}            

/* 
*解析定位错误信息 
*/
function onError(data) {
    var str = '定位失败,';
    str += '错误信息：'
    switch (data.info) {
        case 'PERMISSION_DENIED':
            str += '浏览器阻止了定位操作';
            break;
        case 'POSITION_UNAVAILBLE':
            str += '无法获得当前位置';
            break;
        case 'TIMEOUT':
            str += '定位超时';
            break;
        default:
            str += '未知错误';
            break;
    }
    updateMemberPositions(0,0);
    setLocation();
};

function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {

        xScroll = window.innerWidth + window.scrollMaxX;

        yScroll = window.innerHeight + window.scrollMaxY;

    } else {

        if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac    

            xScroll = document.body.scrollWidth;

            yScroll = document.body.scrollHeight;

        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari    

            xScroll = document.body.offsetWidth;

            yScroll = document.body.offsetHeight;

        }

    }

    var windowWidth, windowHeight;

    if (self.innerHeight) { // all except Explorer    

        if (document.documentElement.clientWidth) {

            windowWidth = document.documentElement.clientWidth;

        } else {

            windowWidth = self.innerWidth;

        }

        windowHeight = self.innerHeight;

    } else {

        if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode    

            windowWidth = document.documentElement.clientWidth;

            windowHeight = document.documentElement.clientHeight;

        } else {

            if (document.body) { // other Explorers    

                windowWidth = document.body.clientWidth;

                windowHeight = document.body.clientHeight;

            }

        }

    }       

    // for small pages with total height less then height of the viewport    

    if (yScroll < windowHeight) {

        pageHeight = windowHeight;

    } else {

        pageHeight = yScroll;

    }    

    // for small pages with total width less then width of the viewport    

    if (xScroll < windowWidth) {

        pageWidth = xScroll;

    } else {

        pageWidth = windowWidth;

    }

    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);

    return arrayPageSize;

}

function popMore(){
	if(document.getElementById("dropbox").style.display=='none'){
		document.getElementById("dropbox").style.display="";
	}else{
		document.getElementById("dropbox").style.display="none";
	}
}


var tripLeaderId = "";
var flag = true;


function updateLocation(stats){
		var loc = {
			Latitude: 29579916,
			Longitude: 11598905	
		};
		
		if(_lat==null || _lat=="undefined"){
			alert("当前位置无法获取，请重试！");
			return false;	
		}
	
		loc.Latitude = parseFloat(String(_lat))*1000000;
		loc.Longitude = parseFloat(String(_lon))*1000000;	
		
		var dataStr = {
      "PickupID" : pickupId,
      "Status" : stats,
      "Loc" : loc
    }; 
    var bodyStr = popBody('UpdateStatusPickup',dataStr);
    var request = popRequest('UpdateStatusPickup',openId,bodyStr);
    //调用了jquery.json 库  
    var encoded = $.toJSON( request );  
    var jsonStr = encoded;  

    $.ajax({  
      url : actionStr,  
      type : 'POST',  
      data : jsonStr,  
      dataType : 'json',  
      contentType : 'application/json',  
      success : function(data, status, xhr) {  
      //         Do Anything After get Return data  
        	if(stats=='1'){
        		
        	}else{
							window.location.href="car_list.html?openid="+openId;
        	}
      },  
      Error : function(xhr, error, exception) {  
          // handle the error.    
          alert(exception.toString());  
      }  
    });  
}

function hiddenVoiceSession(){
	document.getElementById("popup").style.display="none";	
}

function fetchVoiceList(){
	document.getElementById("popup").style.display="";
		var dataStr = {
      "TripID" : parseInt(pickupId, 10),
      "VoiceType": 2,
      "Cursor" : 0,
      "Limit": 10,
      "OpenID" : openId 
    }; 
    var bodyStr = popBody('ListVoice',dataStr);
    var request = popRequest('ListVoice',openId,bodyStr);
    //调用了jquery.json 库  
    var encoded = $.toJSON( request );  
    var jsonStr = encoded;  
    $.ajax({  
      url : actionStr,  
      type : 'POST',  
      data : jsonStr,  
      dataType : 'json',  
      contentType : 'application/json',  
      success : function(data, status, xhr) {  
      //         Do Anything After get Return data  
      	var voiceMsg = "";
      	$.each(data.portalResp.Data.Voices, function(index){
          		var lastestOpenId =  (data.portalResp.Data.Voices[index].OpenID);
		        	var lastestImage =  (data.portalResp.Data.Voices[index].ImageURL);
		        	var lastestVoiceID =  (data.portalResp.Data.Voices[index].VoiceID);
		        	var lastestNickName =  (data.portalResp.Data.Voices[index].NickName);
		        	
		        	if(lastestOpenId!=openId){
				        	voiceMsg+='<div class="call_group">';
							    voiceMsg+='     <div class="fl"><img src="'+lastestImage+'" class="user_pic"></div>';
							    voiceMsg+='     <a href="javascript:void(0);">';
							    voiceMsg+='     <div class="fl message_area ml10">';
							    voiceMsg+='          <p class="fl white_arrow"><img src="img/left_arrow_white.png"></p>';
							    voiceMsg+='          <font onclick="startVoice(\''+lastestVoiceID+'\')"><p class="fl white_message"><i class="iconfont gray">&#xe618;</i></p></font>';
							    voiceMsg+='          <o class="fl message_time ml5"></p>';
							    voiceMsg+='     </div>';
							    voiceMsg+='     </a>';
							    voiceMsg+='</div>';
					  	}else{
					  			voiceMsg+='<div class="call_group">';
							    voiceMsg+='     <div class="fr"><img src="'+lastestImage+'" class="user_pic"></div>';
							    voiceMsg+='     <a href="javascript:void(0);">';
							    voiceMsg+='     <div class="fr message_area mr10">';
							    voiceMsg+='          <p class="fr white_arrow"><img src="img/right_arrow_green.png"></p>';
							    voiceMsg+='          <font onclick="startVoice(\''+lastestVoiceID+'\')"><p class="fr green_message"><i class="iconfont white">&#xe617;</i></p></font>';
							    voiceMsg+='          <o class="fr message_time mr5"></p>';
							    voiceMsg+='     </div>';
							    voiceMsg+='     </a>';
							    voiceMsg+='</div>';
					  	}
          }); 
          document.getElementById("popup").style.height=(getPageSize()[1]-120)+"px";
          document.getElementById("popupMsg").innerHTML = voiceMsg;
      },  
      Error : function(xhr, error, exception) {  
          // handle the error.    
          alert(exception.toString());  
      }  
    });  
}

function switchMenu(){
		var contain = "";
		if(flag){
			if(memberList!=null && memberList.length>0){
				$("#switchMenu").html("");	
				$.each(memberList, function(index){
						var nickName = memberList[index].Nickname;
						var imageURL = memberList[index].ImageURL;
						if(tripLeaderId==memberList[index].OpenID){
							contain+='<div class="user_group highlight"><p><img src="'+imageURL+'" width="30px" height="30px"></p> <p class="user_group_name">'+nickName+'</p></div>';
						}else{
							contain+='<div class="user_group"><p><img src="'+imageURL+'" width="30px" height="30px"></p> <p class="user_group_name">'+nickName+'</p></div>';
						}
		    }); 
		    $("#switchMenu").html(contain);	
	  	}
	  	flag = false;
	  }else{
	  	flag = true;	
	  	contain+='<a href="javascript:void(0);"><div class="btn_3_voice"><p class="ico_group"><i class="iconfont img">&#xe60b;</i>播放</p></div></a>';
	    contain+='<a href="javascript:void(0);"><div class="btn_3_voice line_left"><p class="ico_group"><i class="iconfont img">&#xe616;</i>录音</p></div></a>';
	    contain+='<a href="javascript:void(0);"><div class="btn_3_voice line_left"><p class="ico_group"><i class="iconfont img">&#xe615;</i>会话</p></div></a>';
	    $("#switchMenu").html(contain);	
	  }
}

var pageURL = location.href.split('#')[0];
var voice = {
    localId: '',
    serverId: ''
};

function startVoice(voiceId){
	voice.serverId = voiceId;
	        	
	wx.downloadVoice({
    serverId: voice.serverId,
    success: function (res) {
      voice.localId = res.localId;
      
      if (voice.localId == '') {
	      alert('没有最新的语音信息！');
	      return;
	    }
	    wx.playVoice({
	      localId: voice.localId
	    });
    }
  });
}

function uploadVoiceId(voiceId){
		var dataStr = {
      "TripID" : parseInt(pickupId, 10),
      "VoiceType": 2,
      "VoiceID" : voiceId 
    }; 
    var bodyStr = popBody('UploadVoice',dataStr);
    var request = popRequest('UploadVoice',openId,bodyStr);
    //调用了jquery.json 库  
    var encoded = $.toJSON( request );  
    var jsonStr = encoded;  

    $.ajax({  
      url : actionStr,  
      type : 'POST',  
      data : jsonStr,  
      dataType : 'json',  
      contentType : 'application/json',  
      success : function(data, status, xhr) {  
      //         Do Anything After get Return data  
        	alert("上传语音成功!");
      },  
      Error : function(xhr, error, exception) {  
          // handle the error.    
          alert(exception.toString());  
      }  
    });  
}
  
function loadWechatVoice(){
		var dataStr = {
			PageURL: 	pageURL
		};	
		var bodyStr = popBody('JSSignature',dataStr);
		var request = popRequest('JSSignature',openId,bodyStr);
		//调用了jquery.json 库  
		var encoded = $.toJSON( request );  
		var jsonStr = encoded;  

		$.ajax({  
		url : actionStr,  
		type : 'POST',  
		data : jsonStr,  
		dataType : 'json',  
		contentType : 'application/json',  
		success : function(data, status, xhr) {  
		//         Do Anything After get Return data  
		        var timestamp = data.portalResp.Data.timestamp;
		        var noncestr = data.portalResp.Data.noncestr;
		        var signature = data.portalResp.Data.signature;
		        var appId = data.portalResp.Data.appId;  
		        
		         /*
					   * 注意：
					   * 1. 所有的JS接口只能在公众号绑定的域名下调用，公众号开发者需要先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”。
					   * 2. 如果发现在 Android 不能分享自定义内容，请到官网下载最新的包覆盖安装，Android 自定义分享接口需升级至 6.0.2.58 版本及以上。
					   * 3. 常见问题及完整 JS-SDK 文档地址：http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
					   *
					   * 开发中遇到问题详见文档“附录5-常见错误及解决办法”解决，如仍未能解决可通过以下渠道反馈：
					   * 邮箱地址：weixin-open@qq.com
					   * 邮件主题：【微信JS-SDK反馈】具体问题
					   * 邮件内容说明：用简明的语言描述问题所在，并交代清楚遇到该问题的场景，可附上截屏图片，微信团队会尽快处理你的反馈。
					   */
					  wx.config({
					      debug: false,
					      appId: appId,
					      timestamp: timestamp,
					      nonceStr: noncestr,
					      signature: signature,
					      jsApiList: [
					      	'hideOptionMenu',
					      	'showOptionMenu',
					      	'stopRecord',
					      	'onRecordEnd',
					      	'playVoice',
					      	'pauseVoice',
					      	'stopVoice',
					      	'uploadVoice',
					      	'downloadVoice',
					        'startRecord'
					      ]
					  });
					
					wx.ready(function () {
						
						wx.hideOptionMenu();
					    // 4 音频接口
						  // 4.2 开始录音
						  document.querySelector('#startRecord').onclick = function () {
						  	document.getElementById("stopRecordDiv").style.display="";
						  	//document.getElementById("uploadVoiceDiv").style.display="none";
						  	document.getElementById("startRecordDiv").style.display="none";
						    wx.startRecord({
						      cancel: function () {
						        alert('用户拒绝授权录音');
						      }
						    });
						  };
						
						  // 4.3 停止录音
						  document.querySelector('#stopRecord').onclick = function () {
						  	document.getElementById("stopRecordDiv").style.display="none";
						  	//document.getElementById("uploadVoiceDiv").style.display="";
						  	document.getElementById("startRecordDiv").style.display="";
						    wx.stopRecord({
						      success: function (res) {
						        voice.localId = res.localId;
						        
						        if (voice.localId == '') {
								      alert('请先使用 startRecord 接口录制一段声音');
								      return;
								    }
								    wx.uploadVoice({
								      localId: voice.localId,
								      isShowProgressTips: 1, // 默认为1，显示进度提示
								      success: function (res) {
								        //alert('上传语音成功，serverId 为' + res.serverId);
								        voice.serverId = res.serverId;
								        uploadVoiceId(res.serverId);
								      }
								    });
						      },
						      fail: function (res) {
						        alert(JSON.stringify(res));
						      }
						    });
						  };
						
						  // 4.4 监听录音自动停止
						  wx.onVoiceRecordEnd({
						    complete: function (res) {
						      voice.localId = res.localId;
						      alert('录音时间已超过一分钟');
						    }
						  });
						
						  // 4.5 播放音频
						  document.querySelector('#playVoiceStart').onclick = function () {
								var dataStr = {
						      "TripID" : parseInt(pickupId, 10),
						      "VoiceType": 2,
						      "Cursor" : 0,
						      "Limit": 1,
						      "OpenID" : openId 
						    }; 
						    var bodyStr = popBody('ListVoice',dataStr);
						    var request = popRequest('ListVoice',openId,bodyStr);
						    //调用了jquery.json 库  
						    var encoded = $.toJSON( request );  
						    var jsonStr = encoded;  

						    $.ajax({  
						      url : actionStr,  
						      type : 'POST',  
						      data : jsonStr,  
						      dataType : 'json',  
						      contentType : 'application/json',  
						      success : function(data, status, xhr) {  
						      //         Do Anything After get Return data  
						      		if(data.portalResp.Data.Voices[0].OpenID){
							        	var lastestOpenId =  (data.portalResp.Data.Voices[0].OpenID);
							        	var lastestImage =  (data.portalResp.Data.Voices[0].ImageURL);
							        	var lastestVoiceID =  (data.portalResp.Data.Voices[0].VoiceID);
							        	var lastestNickName =  (data.portalResp.Data.Voices[0].NickName);
							        	voice.serverId = lastestVoiceID;
							        	
							        	wx.downloadVoice({
										      serverId: voice.serverId,
										      success: function (res) {
										        voice.localId = res.localId;
										        
										        if (voice.localId == '') {
												      alert('没有最新的语音信息！');
												      return;
												    }
												    wx.playVoice({
												      localId: voice.localId
												    });
										      }
										    });
									  	}else{
									  		alert("没有最新的语音信息！");	
									  	}
						        	
						      },  
						      Error : function(xhr, error, exception) {  
						          // handle the error.    
						          alert(exception.toString());  
						      }  
						    });  
						  };
						
						
						  // 4.8 监听录音播放停止
						  wx.onVoicePlayEnd({
						    complete: function (res) {
						      //alert('录音（' + res.localId + '）播放结束');
						    }
						  });
						  
						  // 4.8 上传语音
						  document.querySelector('#uploadVoice').onclick = function () {
						  	//alert("开始录音："+voice.localId);
						  	document.getElementById("stopRecordDiv").style.display="none";
						  	document.getElementById("uploadVoiceDiv").style.display="none";
						  	document.getElementById("startRecordDiv").style.display="";
						    if (voice.localId == '') {
						      alert('请先使用 startRecord 接口录制一段声音');
						      return;
						    }
						    wx.uploadVoice({
						      localId: voice.localId,
						      isShowProgressTips: 1, // 默认为1，显示进度提示
						      success: function (res) {
						        //alert('上传语音成功，serverId 为' + res.serverId);
						        voice.serverId = res.serverId;
						        uploadVoiceId(res.serverId);
						      }
						    });
						  };
						  
//						    // 4.9 下载语音
//							  document.querySelector('#downloadVoice').onclick = function () {
//							  	voice.serverId = "OS3TSdDrGN9E4B0ozZhV72ckMWXhMmmYKIKaolmXa4RVhJktrlqjgcRuxJ0xAeR6";
//							    if (voice.serverId == '') {
//							      alert('请先使用 uploadVoice 上传声音');
//							      return;
//							    }
//							    alert("语音ID:"+voice.serverId);
//							    wx.downloadVoice({
//							      serverId: voice.serverId,
//							      success: function (res) {
//							        alert('下载语音成功，localId 为' + res.localId);
//							        voice.localId = res.localId;
//							      }
//							    });
//							  };

					});
				
					wx.error(function (res) {
					  alert(res.errMsg);
					});
		},  
		Error : function(xhr, error, exception) {  
		    // handle the error.    
		    alert(exception.toString());  
		}  
		});  	
	
}

$(document).ready(function(){
  	
	if(openId==null || openId==""){
		return false;	
	}else{
    fillPickupInfo(openId,pickupId);   
    
    loadWechatVoice(); 
	}
	
});
var nickName,imageURL,recNickname,recImg;

function fillPickupInfo(openId,pickupId){
	var dataStr = {
		PickupID: 	pickupId
	};	
	var bodyStr = popBody('PickupDetail',dataStr);
	var request = popRequest('PickupDetail',openId,bodyStr);
	//调用了jquery.json 库  
	var encoded = $.toJSON( request );  
	var jsonStr = encoded;  

	$.ajax({  
	url : actionStr,  
	type : 'POST',  
	data : jsonStr,  
	dataType : 'json',  
	contentType : 'application/json',  
	success : function(data, status, xhr) {  
	//         Do Anything After get Return data  
			
			$("#title").html("");	
			$("#title").html(data.portalResp.Data.Title);		
			
			
			tripLeaderId = data.portalResp.Data.OwnerId;
			receiverId = data.portalResp.Data.Receiver;
			
			imageURL = data.portalResp.Data.SenderPortrait;
			nickName = data.portalResp.Data.SenderName;
			$("#mines").html("");	
			$("#mines").html("<img src='"+imageURL+"'  class='user_pic'>");	
						
			$("#nickname").html("");	
			$("#nickname").html(nickName);
			
			$("#senderImg").attr("src",imageURL);
			$("#receiverImg").attr("src",data.portalResp.Data.ReceiverPortrait);

			
			$("#senderNickname").html("");	
			$("#senderNickname").html(nickName);
			
			$("#receiverNickname").html("");	
			$("#receiverNickname").html(data.portalResp.Data.ReceiverName);
			
			recNickname = data.portalResp.Data.ReceiverName;
			recImg = data.portalResp.Data.ReceiverPortrait;
			
			mapInit(new AMap.LngLat(data.portalResp.Data.Loc.Longitude/1000000, data.portalResp.Data.Loc.Latitude/1000000));
			//mapObj.setFitView();
	},  
	Error : function(xhr, error, exception) {  
	    // handle the error.    
	    alert(exception.toString());  
	}  
	});  	
}

setLocation();
setInterval(setLocation, 30000);
</script>
</html>